import axios from 'axios';

const env = import.meta.env

// 创建 axios 实例的函数
function createAxiosInstance(baseURL) {
    const instance = axios.create({
        baseURL: baseURL,
        timeout: 5000,
    });

    // 请求拦截器
    instance.interceptors.request.use(
        config => {
            // 可以在这里添加请求头信息等
            return config;
        },
        error => {
            return Promise.reject(error);
        }
    );

    // 响应拦截器
    instance.interceptors.response.use(
        response => {
            return response.data;
        },
        error => {
            console.error('请求错误：', error);
            return Promise.reject(error);
        }
    );

    return instance;
}

console.log(env.MODE)

let instance;
let mode = env.MODE;
if(mode==='dev'){
    instance = createAxiosInstance('/dev');
}else if(mode==='dem'){
    instance = createAxiosInstance('/dem');
}else if(mode==='pro'){
    instance = createAxiosInstance(window.location.protocol+"//"+window.location.host+"/messageplus");
}

export default { instance };